package com.lengyue.imakiba.filter;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;

public class PermissionFilter implements Interceptor {
	private static final String USER_ID = "userId";

	@Override
	public void intercept(ActionInvocation ai) {
		if(ai.getController().getClass().getName().startsWith("com.lengyue.imakiba.manage"))
		{
			//manage下用户未登录返回首页
			if(ai.getController().getSessionAttr(USER_ID)==null)
			{
				String contextPath = ai.getController().getRequest().getContextPath();
				ai.getController().redirect(contextPath+"/index");
				return;
			}
		}
		ai.invoke();
	}

}
